layui.define(["table", "form"],
    function (e) {
        var t = layui.$,
            i = layui.table,
            u = layui.util,
            n = layui.form;
        i.render({
            elem: "#app-balance-list",
            //url: "getList",
            //自定义响应字段
            response: {
                statusName: 'code' //数据状态的字段名称
                , statusCode: 1 //数据状态一切正常的状态码
                , msgName: 'msg' //状态信息的字段名称
                , dataName: 'data' //数据详情的字段名称
            },
            cols: [[
                // {
                //     field: "id",
                //     width: 100,
                //     title: "ID",
                //     sort: !0
                // },
                {
                    field: "uid",
                    width: 100,
                    title: "商户UID",
                    sort: !0
                },
                {
                    field: "enable",
                    title: "可用余额",
                    templet: function (d) { return parseFloat(d.enable).toFixed(2); },
                    style: "color:blue;text-align:right;"
                },
                {
                    field: "disable",
                    title: "待结算余额",
                    templet: function (d) { return parseFloat(d.disable).toFixed(2); },
                    style: "color:red;text-align:right;"
                },
                {
                    field: "status",
                    title: "状态",
                    templet: "#buttonTpl",
                    width: 100,
                    align: "center"
                },
                // {
                //     field: "create_time",
                //     title: "创建时间",
                //     width: 180,
                //     sort: !0,
                //     templet: function (d) { return u.toDateString(d.create_time * 1000); }
                // },
                {
                    field: "update_time",
                    title: "更新时间",
                    width: 180,
                    sort: !0,
                    templet: function (d) { return u.toDateString(d.update_time * 1000); }
                },
                {
                    title: "操作",
                    width: 350,
                    align: "center",
                    fixed: "right",
                    toolbar: "#table-balance-list"
                }]],
            page: !0,
            limit: 10,
            limits: [10, 15, 20, 25, 30],
            text: "对不起，加载出现异常！"
        }),
            i.on("tool(app-balance-list)",
                function (e) {
                    console.log(e);
                    if ("changeEnableMoney" === e.event) {
                        t(e.tr);
                        layer.prompt({
                            formType: 0,
                            value: '',
                            title: '请输入可用余额变动金额',
                            area: ['480px', '320px'],
                        }, function (value, index, elem) {
                            var postData = { id: e.data.id, value: value, autoReduction: layui.$("#autoReduction")[0].checked };
                            layui.$.post("changeEnableMoney", postData, function (res) {
                                if (res.code == 1) {
                                    e.update({
                                        enable: res.enable,
                                        disable: res.disable
                                    });
                                    layer.close(index);
                                }
                                layer.msg(res.msg, { icon: res.code == 1 ? 1 : 2, time: 1500 });
                            });
                        });

                        layui.$(".layui-layer-content").append("<input type='checkbox' id='autoReduction' checked='true' /> 从待结算余额扣除");

                    }  if ("changeDisableMoney" === e.event) {
                        t(e.tr);
                        layer.prompt({
                            formType: 0,
                            value: '',
                            title: '请输入待结算余额变动金额',
                            area: ['480px', '320px'] //自定义文本域宽高
                        }, function (value, index, elem) {
                            var postData = { id: e.data.id, value: value };
                            layui.$.post("changeDisableMoney", postData, function (res) {
                                if (res.code == 1) {
                                    e.update({
                                        disable: res.data
                                    });
                                    layer.close(index);
                                }
                                layer.msg(res.msg, { icon: res.code == 1 ? 1 : 2, time: 1500 });
                            });
                        });
                    } else if ("details" === e.event) {
                        t(e.tr);
                        layer.open({
                            type: 2,
                            title: "账户明细",
                            content: "details.html?id=" + e.data.uid,
                            maxmin: !0,
                            area: ['80%', '80%'],
                            yes: function (f, t) { },
                            success: function (e, t) { }
                        })
                    }
                }),

            i.render({
                elem: "#app-balance-details-list",
                //url: 'getDetails',
                //添加请求字段
                where: {
                    uid: t("input[ name='uid' ] ").val()
                },
                //自定义响应字段
                response: {
                    statusName: 'code' //数据状态的字段名称
                    , statusCode: 1 //数据状态一切正常的状态码
                    , msgName: 'msg' //状态信息的字段名称
                    , dataName: 'data' //数据详情的字段名称
                },
                cols: [[{
                    field: "type",
                    templet: "#buttonType",
                    width: 120,
                    title: "资金类型"
                },
                {
                    field: "preinc",
                    width: 100,
                    title: "变动前金额",
                    templet: function (d) { return parseFloat(d.preinc).toFixed(2); },
                    style: "color:blue;text-align:right;"
                },
                {
                    field: "increase",
                    width: 120,
                    title: "变动金额",
                    style: "color:red;text-align:right;",
                    templet: function (d) {
                        if (d.increase > 0) {
                            return "+" + parseFloat(d.increase).toFixed(2);
                        } else if (d.reduce > 0) {
                            return "-" + parseFloat(d.reduce).toFixed(2);
                        } else {
                            return 0.00;
                        }
                    }
                },
                {
                    field: "suffixred",
                    width: 120,
                    title: "变动后金额",
                    templet: function (d) { return parseFloat(d.suffixred).toFixed(2); },
                    style: "color:blue;text-align:right;"
                },
                {
                    field: "remarks",
                    title: "变动备注"
                },
                {
                    field: "update_time",
                    width: 200,
                    title: "更新时间",
                    templet: function (d) { return u.toDateString(d.update_time * 1000); }
                }]],
                page: {
                    limit: 10,
                    limits: [10, 15, 20, 25, 30]
                },
                text: "对不起，加载出现异常！"
            }),
            i.render({
                elem: "#app-order-paid-list",
                //url: 'paidList',
                //自定义响应字段
                response: {
                    statusName: 'code' //数据状态的字段名称
                    , statusCode: 1 //数据状态一切正常的状态码
                    , msgName: 'msg' //状态信息的字段名称
                    , dataName: 'data' //数据详情的字段名称
                },
                cols: [[
                    {
                        field: "uid",
                        width: 80,
                        title: "商户"
                    },
                    {
                        field: "cash_no",
                        width: 200,
                        title: "单号"
                    },
                    {
                        field: "amount",
                        width: 100,
                        title: "交易金额",
                        templet: function (d) { return parseFloat(d.amount).toFixed(2); },
                        style: "color:red;text-align:right;"
                    },
                    {
                        field: "bank_account_name",
                        width: 100,
                        title: "收款人"
                    },
                    {
                        field: "bank_account",
                        width: 180,
                        title: "收款账号"
                    },
                    {
                        field: "remarks",
                        title: "备注"
                    },
                    {
                        field: "update_time",
                        width: 160,
                        title: "更新时间",
                        color: "red",
                        templet: function (d) { return u.toDateString(d.create_time * 1000); }
                    },
                    {
                        field: "status",
                        title: "订单状态",
                        templet: "#buttonTpl",
                        width: 100,
                        align: "center"
                    },
                    {
                        title: "操作",
                        width: 150,
                        align: "center",
                        fixed: "right",
                        toolbar: "#table-balance-tool"
                    }]],
                page: !0,
                limit: 10,
                limits: [10, 15, 20, 25, 30],
                text: "对不起，加载出现异常！",
                done: function () {
                    //加载完成
                }
            }),
            i.on("tool(app-order-paid-list)",
                function (e) {
                    if ("deal" === e.event)
                        layer.confirm("确定审核吗？", function (d) {
                            t.post("deal", { cash_id: e.data.id }, function (res) {
                                layer.msg(res.msg, { icon: res.code == 1 ? 1 : 2, time: 1500 });
                                layer.close(d); //关闭弹层
                                i.reload('app-order-paid-list')
                            });
                        });
                    else if ("rebut" === e.event) {
                        layer.confirm("确定驳回吗？", function (d) {
                            t.post("rebut", { cash_id: e.data.id }, function (res) {
                                layer.msg(res.msg, { icon: res.code == 1 ? 1 : 2, time: 1500 });
                                i.reload('app-order-paid-list')
                            });
                        });
                    }
                }),
                i.render({
                    elem: "#app-order-settlement-list",
                    //url: 'settlementList',
                    //自定义响应字段
                    response: {
                        statusName: 'code' //数据状态的字段名称
                        , statusCode: 1 //数据状态一切正常的状态码
                        , msgName: 'msg' //状态信息的字段名称
                        , dataName: 'data' //数据详情的字段名称
                    },
                    cols: [[
                        {
                            field: "uid",
                            width: 80,
                            title: "商户"
                        },
                        {
                            field: "no",
                            width: 200,
                            title: "单号"
                        },
                        {
                            field: "user_name",
                            width: 100,
                            title: "姓名"
                        },
                        {
                            field: "user_idcard",
                            width: 180,
                            title: "身份证号"
                        },
                        {
                            field: "user_phone",
                            width: 130,
                            title: "手机号码"
                        },
                        {
                            field: "bank_account",
                            width: 180,
                            title: "收款账号"
                        },
                        {
                            field: "bank_name",
                            width: 150,
                            title: "开户银行"
                        },
                        {
                            field: "bank_code",
                            width: 100,
                            title: "银行代码"
                        },
                        {
                            field: "remarks",
                            width: 300,
                            title: "备注"
                        },
                        {
                            field: "update_time",
                            width: 160,
                            title: "更新时间",
                            color: "red",
                            templet: function (d) { return u.toDateString(d.update_time * 1000); }
                        },
                        {
                            field: "amount",
                            width: 120,
                            title: "结算金额",
                            templet: function (d) { return parseFloat(d.amount).toFixed(2); },
                            fixed: "right",
                            style: "color:red;text-align:right;"
                        },
                      
                        {
                            field: "status",
                            title: "订单状态",
                            templet: "#buttonTpl",
                            width: 100,
                            fixed: "right",
                            align: "center"
                        },
                        {
                            title: "操作",
                            width: 150,
                            align: "center",
                            fixed: "right",
                            toolbar: "#table-settlement-tool"
                        }]],
                    page: !0,
                    limit: 10,
                    limits: [10, 15, 20, 25, 30],
                    text: "对不起，加载出现异常！",
                    done: function () {
                        //加载完成
                    }
                }),
                i.on("tool(app-order-settlement-list)",
                    function (e) {
                        if ("settlementDeal" === e.event)
                            layer.confirm("确定完成结算申请吗, 该操作不可撤销？", function (d) {
                                t.post("settlementDeal", { settlement_id: e.data.id }, function (res) {
                                    layer.msg(res.msg, { icon: res.code == 1 ? 1 : 2, time: 1500 });
                                    layer.close(d); //关闭弹层
                                    i.reload('app-order-settlement-list')
                                });
                            });
                        else if ("settlementRebut" === e.event) {
                            layer.prompt({
                                formType: 2,
                                value: '',
                                title: '请输入退回结算原因',
                                area: ['480px', '60px'] //自定义文本域宽高
                            }, function (value, index, elem) {
                                t.post("settlementRebut", { settlement_id: e.data.id, reason: value }, function (res) {
                                    if (res.code == 1) {
                                        i.reload('app-order-settlement-list')
                                        layer.close(index);
                                    }
                                    layer.msg(res.msg, { icon: res.code == 1 ? 1 : 2, time: 1500 });
                                });
                            });
                        }
                    }),
            e("balance", {})
    });